package server;

import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;


import transportDriver.ChatMessage;



public class TrsprtRcvrServer extends ReceiverAdapter {
	
	ChatMessage myChatMessage;
	
    public void receive(Message msg) {
    	
         	
    	
    	         	
        //ServerMain.fenetre.ActualiserTextArea("["+myChatMessage.getSrc()+"] : "+myChatMessage.getData());
        
    	myChatMessage=(ChatMessage)msg.getObject(); 
    	
    	if(myChatMessage.getMessageToBeReadByServer()==true){
    		       	
    		if(myChatMessage.getConnection()==true){
    			
    		    
    			ChatMessage myChatMessage2= new ChatMessage("server",true,false,"toto");
    			myChatMessage2.setMessageToBeReadByServer(false);
    	 		
    			Message msg1=new Message();			     						
    			msg1.setObject(myChatMessage2);	
    							
    			try {										
    			ServerMain.channel.send(msg1);
    			
    			
    			} catch (Exception e1) {
    				
    				e1.printStackTrace();
    			}
    			  
    				
    			}  
    		
    	}
    	
		else{
			
			ServerMain.fenetre.ActualiserTextArea("["+myChatMessage.getSrc()+"] : "+myChatMessage.getData());
    		
    			
    		}
           
       
        

     }
	

}
